package com.tjsinfo.tjsoa.workplan.action;

import java.util.Iterator;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.tjsinfo.tjsoa.system.vo.TSystemUser;
import com.tjsinfo.tjsoa.system.vo.User;
import com.tjsinfo.tjsoa.workplan.bo.IWorkPlanDefineBo;
import com.tjsinfo.tjsoa.workplan.vo.WorkPlanDefine;


/**
 * 添加工作计划表单action
 * @author wangxiaowei
 *
 */
public class AddWorkPlanFromAction extends Action{

	private IWorkPlanDefineBo workPlanDefineBo;
	
	/**
	 * @return the workPlanDefineBo
	 */
	public IWorkPlanDefineBo getWorkPlanDefineBo() {
		return workPlanDefineBo;
	}

	/**
	 * @param workPlanDefineBo the workPlanDefineBo to set
	 */
	public void setWorkPlanDefineBo(IWorkPlanDefineBo workPlanDefineBo) {
		this.workPlanDefineBo = workPlanDefineBo;
	}

	/* (non-Javadoc)
	 * @see org.apache.struts.action.Action#execute(org.apache.struts.action.ActionMapping, org.apache.struts.action.ActionForm, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
	 */
	@Override
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		HttpSession session = request.getSession();
		User user = (User) session.getAttribute("user");
		// TODO Auto-generated method stub
		try {
			String definename = "";
			String defineid = "";
			String type = request.getParameter("type");
			Integer number = Integer.parseInt(request.getParameter("number"));
			Integer year = Integer.parseInt(request.getParameter("year"));
			String time = request.getParameter("time");
			//WorkPlanDefine workPlanDefine = workPlanDefineBo.selectDefineAndType(type, user.getUser_id());
			List list =  workPlanDefineBo.selectDefineAndTypeList(user.getUser_id());
			request.setAttribute("type", type);
			request.setAttribute("number", number);
			request.setAttribute("year", year);
			request.setAttribute("time", time);
			if (list.size() <= 0 ) {
				request.setAttribute("define", "");
				request.setAttribute("definename", "");
			} else {
				
				// request.setAttribute("define", workPlanDefine.getTjsUserByDefineId().getId().toString());
				if (list.size() >0) {
					for (Iterator iterator = list.iterator(); iterator
							.hasNext();) {
						WorkPlanDefine planDefine = (WorkPlanDefine)iterator.next();
						definename +=","+planDefine.getTjsUser().getUserName();
						defineid +=","+planDefine.getUserId();
						
					}
					request.setAttribute("definename", definename);
					request.setAttribute("define", "");
				} else {
					request.setAttribute("definename", "");
				}
			}
			
			return mapping.findForward("ok");
		} catch (RuntimeException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			
		}
		return mapping.findForward("error");
	}
	
}
